package com.example.myapplication.activity;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.ImageDecoder;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myapplication.R;

public class MainActivity extends AppCompatActivity {
    private TextView textView1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null) {
            actionBar.hide();
        }

        textView1 = (TextView) findViewById(R.id.textView1);
        textView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,activity_login.class);
                startActivityForResult(intent, 1);
            }
        });

        ImageView img_gif = findViewById (R.id.img_gif);
        //如果系统版本为Android9.0以上,则利用新增的AnimatedImageDrawable显示GIF动画
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            try {
                //利用Android9.0新增的ImageDecoder读取gif动画
                ImageDecoder.Source source = ImageDecoder.createSource (getResources (), R.drawable.mainbackground);
                //从数据源中解码得到gif图形数据
                Drawable drawable = ImageDecoder.decodeDrawable (source);
                //设置图像视图的图形为gif图片
                img_gif.setImageDrawable (drawable);
                //如果是动画图形，则开始播放动画
                if (drawable instanceof Animatable) {
                    Animatable animatable = (Animatable) img_gif.getDrawable ();
                    animatable.start ();
                }
            } catch (Exception e) {
                e.printStackTrace ();
            }
        }


    }
}